package com.aabte.commons.errorcode.exception;

import com.aabte.commons.errorcode.IResponseCode;
import java.text.MessageFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author Daniel
 * @version 1.0
 * @date 2020/4/30
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BaseException extends RuntimeException {

  private IResponseCode responseCode;
  private Object[] args;
  private String errorMessageTemplate;

  public BaseException(IResponseCode responseCode) {
    this.responseCode = responseCode;
  }

  public BaseException(IResponseCode responseCode, String errorMessageTemplate, Object[] args) {
    super(MessageFormat.format(errorMessageTemplate, args));
    this.responseCode = responseCode;
    this.args = args;
    this.errorMessageTemplate = errorMessageTemplate;
  }

  public BaseException(IResponseCode responseCode, String errorMessageTemplate, Object[] args,
      Throwable cause) {
    super(MessageFormat.format(errorMessageTemplate, args), cause);
    this.responseCode = responseCode;
    this.args = args;
    this.errorMessageTemplate = errorMessageTemplate;
  }

}
